﻿using System;
using Microsoft.SharePoint;

namespace SPRepository
{
    public class AnnouncementContentType : ItemContentType, IContentType<AnnouncementContentTypeDto>
    {
        #region FieldTypes

        public MultilineTextFieldType Body
        {
            get { return new MultilineTextFieldType(SPBuiltInFieldId.Body); }
        }

        public DateTimeFieldType Expires
        {
            get { return new DateTimeFieldType(SPBuiltInFieldId.Expires); }
        }

        #endregion

        public new AnnouncementContentTypeDto Get(object item)
        {
            var baseDto = base.Get(item);

            var spListItem = item as SPListItem;
            var body = Body.GetValue(spListItem);
            var expires = Expires.GetValue(spListItem);

            return new AnnouncementContentTypeDto(body, expires, baseDto);
        }

        public void Update(object item, AnnouncementContentTypeDto dto)
        {
            base.Update(item, dto);

            var spListItem = item as SPListItem;
            Body.SetValue(spListItem, dto.Body);
            Expires.SetValue(spListItem, dto.Expires);
        }

        public override string GetContentTypeIdDefinition()
        {
            return SPBuiltInContentTypeId.Announcement.ToString();
        }
    }
}